added Feb 2001 SDK
[windows-sources.git] / shared source / sscli20 / jscript / engine / errorconstructor.cs
blobc501f08a21eb08bdfd8f623f4f9faece2422e103
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
13 //
14 // ==--==
16 namespace Microsoft.JScript {
18 using System;
19 using System.Diagnostics;
21 public enum ErrorType : int {OtherError, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError};
23 public sealed class ErrorConstructor : ScriptFunction{
24 internal static readonly ErrorConstructor ob = new ErrorConstructor();
25 internal static readonly ErrorConstructor evalOb = new ErrorConstructor("EvalError", ErrorType.EvalError);
26 internal static readonly ErrorConstructor rangeOb = new ErrorConstructor("RangeError", ErrorType.RangeError);
27 internal static readonly ErrorConstructor referenceOb = new ErrorConstructor("ReferenceError", ErrorType.ReferenceError);
28 internal static readonly ErrorConstructor syntaxOb = new ErrorConstructor("SyntaxError", ErrorType.SyntaxError);
29 internal static readonly ErrorConstructor typeOb = new ErrorConstructor("TypeError", ErrorType.TypeError);
30 internal static readonly ErrorConstructor uriOb = new ErrorConstructor("URIError", ErrorType.URIError);
32 private ErrorPrototype originalPrototype;
33 private ErrorType type;
34 private GlobalObject globalObject;
36 internal ErrorConstructor()
37 : base(ErrorPrototype.ob, "Error", 2) {
38 this.originalPrototype = ErrorPrototype.ob;
39 ErrorPrototype.ob._constructor = this;
40 this.proto = ErrorPrototype.ob;
41 this.type = ErrorType.OtherError;
42 this.globalObject = GlobalObject.commonInstance;
45 internal ErrorConstructor(LenientFunctionPrototype parent, LenientErrorPrototype prototypeProp, GlobalObject globalObject)
46 : base(parent, "Error", 2) {
47 this.originalPrototype = prototypeProp;
48 prototypeProp.constructor = this;
49 this.proto = prototypeProp;
50 this.type = ErrorType.OtherError;
51 this.globalObject = globalObject;
52 this.noExpando = false;
55 internal ErrorConstructor(String subtypeName, ErrorType type)
56 : base(ErrorConstructor.ob.parent, subtypeName, 2){
57 this.originalPrototype = new ErrorPrototype(ob.originalPrototype, subtypeName);
58 this.originalPrototype._constructor = this;
59 this.proto = this.originalPrototype;
60 this.type = type;
61 this.globalObject = GlobalObject.commonInstance;
64 internal ErrorConstructor(String subtypeName, ErrorType type, ErrorConstructor error, GlobalObject globalObject)
65 : base(error.parent, subtypeName, 2){
66 this.originalPrototype = new LenientErrorPrototype((LenientFunctionPrototype)error.parent, error.originalPrototype, subtypeName);
67 this.noExpando = false;
68 this.originalPrototype._constructor = this;
69 this.proto = this.originalPrototype;
70 this.type = type;
71 this.globalObject = globalObject;
72 this.noExpando = false;
75 internal override Object Call(Object[] args, Object thisob){
76 return this.Construct(args);
79 internal override Object Construct(Object[] args){
80 return this.CreateInstance(args);
83 internal ErrorObject Construct(Object e){
84 if (!(e is JScriptException) || this != this.globalObject.originalError){
85 switch (this.type){
86 case ErrorType.EvalError: return new EvalErrorObject(this.originalPrototype, e);
87 case ErrorType.RangeError: return new RangeErrorObject(this.originalPrototype, e);
88 case ErrorType.ReferenceError: return new ReferenceErrorObject(this.originalPrototype, e);
89 case ErrorType.SyntaxError: return new SyntaxErrorObject(this.originalPrototype, e);
90 case ErrorType.TypeError: return new TypeErrorObject(this.originalPrototype, e);
91 case ErrorType.URIError: return new URIErrorObject(this.originalPrototype, e);
92 default: return new ErrorObject(this.originalPrototype, e);
95 switch (((JScriptException)e).GetErrorType()){
96 case ErrorType.EvalError: return this.globalObject.originalEvalError.Construct(e);
97 case ErrorType.RangeError: return this.globalObject.originalRangeError.Construct(e);
98 case ErrorType.ReferenceError: return this.globalObject.originalReferenceError.Construct(e);
99 case ErrorType.SyntaxError: return this.globalObject.originalSyntaxError.Construct(e);
100 case ErrorType.TypeError: return this.globalObject.originalTypeError.Construct(e);
101 case ErrorType.URIError: return this.globalObject.originalURIError.Construct(e);
102 default: return new ErrorObject(this.originalPrototype, e);
106 [JSFunctionAttribute(JSFunctionAttributeEnum.HasVarArgs)]
107 public new ErrorObject CreateInstance(params Object[] args){
108 switch (this.type){
109 case ErrorType.EvalError: return new EvalErrorObject(this.originalPrototype, args);
110 case ErrorType.RangeError: return new RangeErrorObject(this.originalPrototype, args);
111 case ErrorType.ReferenceError: return new ReferenceErrorObject(this.originalPrototype, args);
112 case ErrorType.SyntaxError: return new SyntaxErrorObject(this.originalPrototype, args);
113 case ErrorType.TypeError: return new TypeErrorObject(this.originalPrototype, args);
114 case ErrorType.URIError: return new URIErrorObject(this.originalPrototype, args);
115 default: return new ErrorObject(this.originalPrototype, args);
119 [JSFunctionAttribute(JSFunctionAttributeEnum.HasVarArgs)]
120 public Object Invoke(params Object[] args){
121 return this.CreateInstance(args);